from django.db import models
from django.contrib.contenttypes.models import ContentType

from assets.models import Format

class PreCacheRule_Argument(models.Model):
  class Meta:
    db_table = 'PreCacheRule_Arguments'
    unique_together = (("precache", "name"),)
  precache = models.ForeignKey('PreCacheRule', related_name='arguments')
  name = models.CharField(max_length=255, unique=True)
  value = models.CharField(max_length=4096)
  
class PreCacheRule(models.Model):
  class Meta:
    db_table = 'PreCacheRules'
    verbose_name_plural = "PreCacheRules"
    #unique_together = (("dstFormat", "arguments"),)
  
  name = models.CharField(max_length=255, unique=True)
  srcFormats = models.ManyToManyField(Format, symmetrical=False)
  dstFormat = models.ForeignKey(Format, related_name='+', blank=True, null=True)
  #arguments = models.ManyToManyField(PreCacheRule_Argument, symmetrical=False)

  def __unicode__(self):
    return '%s => %s'%(unicode([f.name for f in self.srcFormats.all()]), self.dstFormat.name if self.dstFormat else 'None')

